//
//  XJYSingleTableViewCell.m
//  ShopMall
//
//  Created by XJY on 17/1/21.
//  Copyright © 2017年 XinJinYing. All rights reserved.
//

#import "XJYSingleTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface XJYSingleTableViewCell ()

@property (nonatomic, strong) UIImageView *iconImage;   //图片
@property (nonatomic, strong) UIImageView *countryImage; //国旗
@property (nonatomic, strong) UILabel *titleLable;      //标题
@property (nonatomic, strong) UILabel *contentLabel;    //内容
@property (nonatomic, strong) UILabel *priceLabel;     //价格label
@property (nonatomic, strong) UIButton *buyCarBtn;     //购物车按钮

@end

@implementation XJYSingleTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.iconImage];
        [self addSubview:self.countryImage];
        [self addSubview:self.titleLable];
        [self addSubview:self.contentLabel];
        [self addSubview:self.priceLabel];
        [self addSubview:self.buyCarBtn];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    
    [_iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(140, 140));
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.left.equalTo(weakSelf.mas_left).offset(5);
    }];
    
    [_countryImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 20));
        make.left.equalTo(weakSelf.iconImage.mas_left).offset(8);
        make.top.equalTo(weakSelf.iconImage.mas_top).offset(8);
    }];
    
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.left.equalTo(weakSelf.iconImage.mas_right).offset(6);
        make.top.equalTo(weakSelf.mas_top).offset(25);
        make.height.equalTo(@15);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLable.mas_bottom).offset(7);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.left.equalTo(weakSelf.iconImage.mas_right).offset(6);
        make.height.equalTo(@60);
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@15);
        make.left.equalTo(weakSelf.iconImage.mas_right).offset(6);
        make.right.equalTo(weakSelf.buyCarBtn.mas_left).offset(-20);
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-23);
    }];
    
    [_buyCarBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(37, 37));
        make.right.equalTo(weakSelf.mas_right).offset(-45);
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-20);
    }];

}

#pragma mark - 给数据赋值
//- (void)setSingleModel:(XJYSingleListModel *)singleModel
//{
//    _singleModel = singleModel;
//    _titleLable.text = singleModel.Title;
//    _contentLabel.text = singleModel.GoodsIntro;
//    [_countryImage sd_setImageWithURL:[NSURL URLWithString:singleModel.CountryImg]];
//    [_iconImage sd_setImageWithURL:[NSURL URLWithString:singleModel.ImgView]];
//    [self priceAttributedString];
//}

//给价格设置不用样式的文字格式
- (void)priceAttributedString{
    //当前价格
    NSString *nowPrice = [NSString stringWithFormat:@"￥%@ ",_singleModel.DomesticPrice];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:nowPrice attributes:@{NSForegroundColorAttributeName : RGB(230, 51, 37), NSFontAttributeName : [UIFont boldSystemFontOfSize:18.0]}];
    
    //过去价格，带删除线
    NSString *oldString = [NSString stringWithFormat:@"%@ ",_singleModel.Price];
    NSMutableAttributedString *oldPrice = [[NSMutableAttributedString alloc] initWithString:oldString attributes:@{NSForegroundColorAttributeName : RGB(132, 132, 132), NSFontAttributeName : [UIFont systemFontOfSize:12.0], NSStrikethroughStyleAttributeName : @(2)}];
    [string insertAttributedString:oldPrice atIndex:string.length];
    _priceLabel.attributedText = string;
    
}

#pragma mark - 懒加载
- (UIImageView *)iconImage
{
    if (!_iconImage) {
        _iconImage = [[UIImageView alloc] init];
    }
    return _iconImage;
}

- (UIImageView *)countryImage
{
    if (!_countryImage) {
        _countryImage = [[UIImageView alloc] init];
    }
    return _countryImage;
}

- (UILabel *)titleLable
{
    if (!_titleLable) {
        _titleLable = [[UILabel alloc] init];
        _titleLable.font = [UIFont boldSystemFontOfSize:14.0];
        _titleLable.textColor = RGB(81, 81, 81);
    }
    return _titleLable;
}

- (UILabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.textColor = RGB(35, 35, 35);
        _contentLabel.font = [UIFont systemFontOfSize:13.0];
        _contentLabel.numberOfLines = 3;
    }
    return _contentLabel;
}

- (UILabel *)priceLabel{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc]init];
    }
    return _priceLabel;
}

- (UIButton *)buyCarBtn{
    if (!_buyCarBtn) {
        _buyCarBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_buyCarBtn setImage:[UIImage imageNamed:@"限时特卖界面购物车图标"] forState:(UIControlStateNormal)];
    }
    return _buyCarBtn;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}



@end
